﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using CH.Easy.DbProvider.Common;
using CH.Easy.DbProvider.Core;

namespace CH.Easy.DbProvider.ExpressionExtend
{
    public class InnerJoinExpression : Expression
    {

        public Expression Expression { get; set; }
        public Type InnerType { get; set; }
        public Expression Inner { get; set; }
        public Expression InnerKey { get; set; }
        public Type OutType { get; set; }
        public Expression Out { get; set; }
        public Expression OutKey { get; set; }
        public ColumnExpression Column { get; set; }
        public InnerJoinExpression(Expression expression)
        {
            this.Expression = expression;
        }
        public InnerJoinExpression(Expression expression, Expression outExp, Expression innerExp, Expression innerKeyEx, Expression outKeyExp, Expression columnExp)
        {
       
            this.Expression = expression;
            this.InnerType = DbProviderHelper.GetElementType(innerExp.Type);
            this.Inner = Expression.Constant((IQueryable)Activator.CreateInstance(
                       typeof(DbTable<>).MakeGenericType(this.InnerType),
                       new object[] { null, null }));
            this.InnerKey = innerKeyEx;
            this.OutType = DbProviderHelper.GetElementType(outExp.Type);
            this.Out = Expression.Constant((IQueryable)Activator.CreateInstance(
                       typeof(DbTable<>).MakeGenericType(this.OutType),
                       new object[] { null, null }));
            this.OutKey = outKeyExp;
            this.Column = new ColumnExpression(columnExp);
        }
        public override ExpressionType NodeType
        {
            get
            {
                return (ExpressionType)ExpressionTypeExend.InnerJoin;
            }
        }

    }
}
